-- attack_poison
-- created by zhuangsl
-- 攻击附带中毒

return {
    apply = function(prop, baseValue)
        return baseValue;
    end,

    -- 攻击触发
    trigger = function(who, prop, arg)
        local target = arg;
        -- 概率触发

        local rand = DungeonM.getRandSeed("attack_poison") % 1000;
        if (rand > prop[3]) then
            return;
        end

        local propId = PropM.getPropId("poisoned");
        -- 中毒威力
        local v;
        -- 伤害=魔力时
        if prop[2] == "magic" then
            local floor = DungeonM.currentLayer();
            local dungeonId = DungeonM.getDungeonId();
            if dungeonId == nil then
                dungeonId = ME.user.dbase:query("currentDungeon");
            end
            local layerFix = DungeonAreaM.query(dungeonId,"layer_fix");
            local magic = who:getMagic();
            v = math.modf(magic * 60000 / floor / (60 + layerFix))+1;
        else
            v = prop[2];
        end

        -- 持续时间，没有配置则默认为9
        local round = CombatM.getRound();
        if prop[4] > 0 then
            round = round + prop[4]
        else
            round = round + 9;
        end
        
        -- 减益状态
        local arr = ({ propId, 1, v, round, });
        local condition = {
            ["prop"] = arr,
            ["end_round"] = round,
        };

        -- 附加状态
        CombatStatusM.applyStatus(target, "poisoned", condition);
        

        return arr;
    end,

    record = function(target, prop, path)
        return false;
    end
};
